import java.io.*;
import java.net.*;

public class Server_Graph {
    public static void main(String[] args) throws Exception {
        String readline = null;
        String inTemp = null;
        //String outTemp = null;
        String turnLine = "\n";
        final String client = "Client:";
        final String server = "Server:";
        
        int port = 4000;

        ServerSocket serverSocket = new ServerSocket(port);
        Socket socket = serverSocket.accept();

        BufferedReader systemIn = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        PrintWriter socketOut = new PrintWriter(socket.getOutputStream());
        
        while(readline != "end"){
            
            inTemp = socketIn.readLine();
            System.out.println(client + turnLine + inTemp);
            // System.out.println(server);
            
            // readline = systemIn.readLine();

            String[] cmd_in= inTemp.split(" ");

            String cmd = "python client.py " + cmd_in[0] + " " + cmd_in[1] + " "+ cmd_in[2];

            System.out.println(cmd);

            Process pr = Runtime.getRuntime().exec(cmd);
            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line2;
            while ((line2 = in.readLine()) != null) {
                System.out.println(line2);
            }
            in.close();
            pr.waitFor();

            File file = new File("out.txt");
            BufferedReader reader = null;
            String tempString = null;
            
            String result = "";
            try {
                reader = new BufferedReader(new FileReader(file));
                while ((tempString = reader.readLine()) != null) {
                    result += tempString + "X";
                }
                reader.close();
                // System.out.print(result);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally{
                if(reader != null){
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            System.out.print(result);

            socketOut.println(result);
            socketOut.flush();    //赶快刷新使Client收到，也可以换成socketOut.println(readline, ture)
            
            //outTemp = readline;
            
            //System.out.println(server);
        }
        
        systemIn.close();
        socketIn.close();
        socketOut.close();
        socket.close();
        serverSocket.close();
    }
}
